package com.naire.modul.project.service;

import java.util.ArrayList;
import java.util.List;

import net.common.manager.SystemCodeManager;
import net.common.service.GeneralService;

import com.naire.modul.projecperiods.vo.ProjecperiodsVo;
import com.naire.modul.project.dao.ProjectDao;
import com.naire.modul.project.dao.impl.ProjectDaoImpl;
import com.naire.modul.project.vo.ProjectVo;

/**
 * 
 * 
 * @author Administrator
 * 
 */
public class ProjectEditorService extends GeneralService {

	private ProjectVo bean;
	private List<ProjecperiodsVo> voes = new ArrayList<ProjecperiodsVo>();
	private Integer project_id;
	
	@Override
	public void execute() throws Exception {
		ProjectDao dao = new ProjectDaoImpl();
		if (bean.getProject_id() != null) {
			dao.update(bean);
		} else {
			Integer nper = bean.getNper() != null ? bean.getNper() : 0;
			Integer times = bean.getTimes() != null ? bean.getTimes() : 0;
			bean.setFlag(0);
			bean.setStatus("0014");
			bean.setProject_num(SystemCodeManager.createCode("0010"));
			project_id = dao.insert(bean);
			for (int i = 0; i < nper; i++) {
				ProjecperiodsVo pv = new ProjecperiodsVo();
				pv.setPeriods_name("");
				pv.setTimes(times);
				voes.add(pv);
			}
		}
	}

	public void setBean(ProjectVo bean) {
		this.bean = bean;
	}

	public List<ProjecperiodsVo> getVoes() {
		return voes;
	}

	public Integer getProject_id() {
		return project_id;
	}
}
